<template>
	<view class="resultTask">
		<uni-nav-bar
			color="#ffffff"
			background-color="#00aded"
			:statusBar="true"
			title="汽运抽查"
			fixed="true"
			left-icon="left"
			left-text="返回"
			@clickLeft="back"
			@clickRight="arrow"
			right-text="实绩"
			right-icon="right"
		></uni-nav-bar>
		<view class="resultTask_top" v-if="transOrderId == null">
			<uni-section title="厂内车辆数量" type="line" titleFontSize="20px">
				<template v-slot:right>
					<view style="font-size: 14px; color: #000; font-weight: 700">总{{ totalCapacityNum }}辆</view>
				</template>
				<view v-for="(item, index) in factoryCapacityList" :key="index" class="factoryCapacityList">
					<text>{{ item.name }}</text>
					<text>{{ item.num }}</text>
				</view>
			</uni-section>
		</view>
		<view class="" style="margin-top: 10rpx; margin-bottom: 10rpx"></view>
		<view class="resultTask_middle">
			<uni-section title="厂内运单信息" type="line" title-font-size="20px">
				<dil-search :columnData="options.columnDataList" @onSearch="onSearch" v-if="options.columnDataList.length > 0"></dil-search>
				<dil-card class="dilCard" @emitEvent="emitEvent" v-bind.sync="options"></dil-card>
			</uni-section>
		</view>
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
export default {
	data() {
		return {
			stepList: [],
			transOrderId: null,
			transOrderNumber: null,
			addressMap: {},
			resultStartTime: null,
			formValue: {},
			factoryCapacityList: [],
			totalCapacityNum: 0,
			options: {
				requestUrl: '/api/v1/tms/getTransOrderList?apiId=627',
				requestQuery: {},
				cardSlotList: [
					{
						label: '作业详情',
						icon: 'bars',
						emitEvent: 'transOrderDetails',
						noPre: '1'
					}
				],
				columnDataList: [],
				totalNum: 0
			}
		};
	},
	onShow() {
		this.getOrderSection();
		this.getFactoryCapacityNum();
	},
	mounted() {
		this.getOrderSectionDebounce = this.Tool.debounce((data) => {
			this.getOrderSection(data);
		}, 500);
	},
	methods: {
		onSearchOrder(item) {
			this.getOrderSectionDebounce(item);
		},
		back() {
			uni.switchTab({
				url: '/pages/index/index'
			});
		},
		async getOrderSection(data = {}) {
			data.deleted = 5;
			this.options.requestQuery = { ...data };
		},
		async getFactoryCapacityNum() {
			const res = await this.$myRequest({
				url: '/api/v1/report/getFactoryCarNum?apiId=662',
				data: {}
			});
			this.factoryCapacityList = res.data.data.list || [];
			this.totalCapacityNum = this.factoryCapacityList.reduce((prev, item) => {
				return prev + item.num;
			}, 0);
		},
		emitEvent(eventName, cardItem) {
			this[eventName](cardItem);
		},
		transOrderDetails(item) {
			this.updateTransOrderItem(item);
			uni.navigateTo({
				url: '/pages/transOrder/transOrderDetail'
			});
		},
		//vuex
		...mapMutations('common', ['updateTransOrderItem'])
	}
};
</script>

<style lang="scss" scoped>
.resultTask {
	width: 100vw;
	height: 100%;
	background-color: #f5f5f5;
	display: flex;
	justify-content: center;
	align-items: center;
	flex-direction: column;
	&_top {
		width: 100vw;
		height: 100%;
		.uni-section {
			width: 100vw;
			/deep/.uni-section-content {
				display: flex;
				justify-content: center;
				align-items: center;
				flex-direction: column;
				.factoryCapacityList {
					width: 100%;
					display: flex;
					justify-content: space-around;
					align-items: center;
					font-size: 14px;
					color: #000;
					font-weight: 700;
					margin: 10rpx 0 10rpx 0;
				}
			}
		}
	}
	&_middle {
		margin-top: 20rpx;
		.uni-section {
			width: 100vw;
			/deep/.uni-section-content {
				display: flex;
				justify-content: center;
				align-items: center;
				flex-direction: column;
			}
		}
	}
	&_floot {
		width: 100vw;
		background-color: #fff;
		margin-top: 20rpx;
		margin-bottom: 20rpx;
		border-radius: 20rpx;
	}
}
</style>
